<?php

namespace App\Repository\CommissionReturn;

use App\Models\CommissionReturn\CommissionReturnModel as Model;
use App\Repository\BaseRepository;

class CommissionReturnRepository extends BaseRepository
{
    public $model;
    public $log;

    public function __construct()
    {
        $this->model = new Model();
//    $this->log = new Logger('anchor');
//    $this->log->pushHandler(
//      (new RotatingFileHandler(storage_path('/logs/anchor.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
//    );
        parent::__construct();
    }

    //列表
    public function index($where, $page = 1, $limit = 10)
    {
        $where = [];
        if (!empty($params['product_id'])) {
            $where['where']['product_id'] = $params['product_id'];
        }
        if (!empty($params['dateRange'])) {
            $time = $params['dateRange'];
            $where['between']['deplete_at'] = $time;
        }
        return $this->unifiedGetPage($where, $page, $limit);
    }

    //删除指定id的内容
    public function del($id)
    {
        $shopId = 0;
        return $this->unifiedDel($id, $shopId);
    }

//新增内容
    public function add($postData)
    {
        if (isset($postData['deplete_at']) && !empty($postData['deplete_at'])) {
            $postData['billing'] = date('Ym', strtotime($postData['deplete_at']));
        }
        return $this->unifiedAdd($postData, [
            'product_id' => '产品名称必填写',
            'deplete_at' => '消耗时间必填写',
            'deplete_money' => '消耗金额必填写',
            'received_money' => '已收款必填写',
            'province' => '产品归属省必填写',
            'city' => '产品归属市必填写'
        ], null);
    }

//修改内容
    public function edit($postData)
    {
        if (isset($postData['deplete_at']) && !empty($postData['deplete_at'])) {
            $postData['billing'] = date('Ym', strtotime($postData['deplete_at']));
        }
        return $this->unifiedEdit($postData, [
            'id' => '请指明修改的数据编号',
            'product_id' => '产品名称必填写',
            'deplete_at' => '消耗时间必填写',
            'deplete_money' => '消耗金额必填写',
            'received_money' => '已收款必填写',
            'province' => '产品归属省必填写',
            'city' => '产品归属市必填写'
        ], null);
    }
}
